package com.lp.easymethodlink.model;

import java.util.ArrayList;
import java.util.List;

/**
 * 调用链路节点
 */
public class CallHierarchyNode {
    // 类名
    private String className;
    
    // 方法名
    private String methodName;
    
    // 方法描述（来自注释）
    private String methodDescription;
    
    // API路径（如果是Controller方法）
    private String apiPath;
    
    // HTTP方法（如果是Controller方法）
    private String httpMethod;
    
    // 子节点
    private List<CallHierarchyNode> children = new ArrayList<>();
    
    // 父节点
    private CallHierarchyNode parent;
    
    public CallHierarchyNode(String className, String methodName) {
        this.className = className;
        this.methodName = methodName;
    }
    
    // Getters and Setters
    public String getClassName() {
        return className;
    }
    
    public void setClassName(String className) {
        this.className = className;
    }
    
    public String getMethodName() {
        return methodName;
    }
    
    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }
    
    public String getMethodDescription() {
        return methodDescription;
    }
    
    public void setMethodDescription(String methodDescription) {
        this.methodDescription = methodDescription;
    }
    
    public String getApiPath() {
        return apiPath;
    }
    
    public void setApiPath(String apiPath) {
        this.apiPath = apiPath;
    }
    
    public String getHttpMethod() {
        return httpMethod;
    }
    
    public void setHttpMethod(String httpMethod) {
        this.httpMethod = httpMethod;
    }
    
    public List<CallHierarchyNode> getChildren() {
        return children;
    }
    
    public void addChild(CallHierarchyNode child) {
        child.setParent(this);
        this.children.add(child);
    }
    
    public CallHierarchyNode getParent() {
        return parent;
    }
    
    public void setParent(CallHierarchyNode parent) {
        this.parent = parent;
    }
    
    public boolean isControllerMethod() {
        return apiPath != null && !apiPath.isEmpty();
    }
    
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(className).append(".").append(methodName);
        if (isControllerMethod()) {
            sb.append(" (").append(httpMethod).append(" ").append(apiPath).append(")");
        }
        return sb.toString();
    }
}